#pragma once

namespace LSH
{

class StringConvert
{
public:
    //------------------------------------------------------------------------------
    inline static size_t ansiToUnicode(const char* pSrcStr, size_t srcLen, wchar_t* pDestStr, size_t destLen)
    {
        return (size_t)MultiByteToWideChar(CP_ACP, 0, pSrcStr, (int)srcLen, (LPWSTR)pDestStr,(int)destLen);
    }

    //------------------------------------------------------------------------------
    inline static size_t unicodeToAnsi(const wchar_t* pSrcStr, size_t srcLen, char* pDestStr, size_t destLen)
    {
        return (size_t)WideCharToMultiByte(CP_ACP, 0, pSrcStr, (int)srcLen, (LPSTR)pDestStr, destLen, NULL, NULL);
    }
#if 0
    //------------------------------------------------------------------------------
    inline static size_t ansiToUnicode(const char* pSrcStr, size_t srcLen, wchar_t* pDestStr, size_t destLen)
    {
        return mbstowcs(DestStr,SrcStr,SrcLen);
    }

    //------------------------------------------------------------------------------
    inline static size_t unicodeToAnsi(const wchar_t* pSrcStr, size_t srcLen, char* pDestStr, size_t destLen)
    {
        return wcstombs(DestStr,SrcStr,SrcLen);
    }
#endif
    //------------------------------------------------------------------------------
    inline static void ascii2WideString(const std::string& szStr, std::wstring& wszStr)
    {
        int length = MultiByteToWideChar(CP_ACP, 0, szStr.c_str(), -1, NULL, NULL);
        wszStr.resize(length);
        LPWSTR lpwszStr = new wchar_t[length];
        MultiByteToWideChar(CP_ACP, 0, szStr.c_str(), -1, lpwszStr, length);
        wszStr.assign(lpwszStr);
        delete[] lpwszStr;
    }

    //------------------------------------------------------------------------------
    inline static void wide2AsciiString(const std::wstring& wszStr, std::string& szStr)
    {
        int nLength = WideCharToMultiByte(CP_ACP, 0, wszStr.c_str(), -1, NULL, NULL, NULL, NULL);
        szStr.resize(nLength);
        LPSTR lpszStr = new char[nLength];
        WideCharToMultiByte(CP_ACP, 0, wszStr.c_str(), -1, lpszStr, nLength, NULL, NULL);
        szStr.assign(lpszStr);
        delete[] lpszStr;
    }

    //------------------------------------------------------------------------------
    inline static void format(std::string& text, const char* pFormat, va_list args){
        char buffer[1024];
        int num =_vsnprintf_s(buffer, 1024, pFormat, args);
        buffer[1023] = '\0';
        text.assign(buffer);
    }

    //------------------------------------------------------------------------------
    inline static void format(std::wstring& text, const wchar_t* pFormat, va_list args){
        wchar_t buffer[1024];
        _vsnwprintf_s(buffer, 1024, pFormat, args);
        buffer[1023] = '\0';
        text.assign(buffer);
    }
};

} // LSH

